<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use App\user_att;
use App\User;

class UserController extends Controller
{
   
    public function user_list(){


        //显示网页        


        // $users=DB::table('Users')->get();
        $count=DB::table('users')->count();
        $users = DB::table('users')
            ->leftJoin('user_atts', 'user_atts.id', '=', 'users.id')
            ->get();


        $u=[
            'users'=>$users,
            'count'=>$count,
        ];
        return view('Admin/user_list',$u);
    }


    public function del($id){
        // echo $id;
        // var_dump(DB::table('Users')->where('id',$id)->delete());
        $req=DB::table('Users')->where('id',$id)->delete();
        if($req){
            return redirect('/Admin/user_list');
        }else{
            echo 'false';
        };
    }

    public function member_show($id){
//        echo "member_Grading";

            $count=DB::table('users')->where('id',$id)->count();
            //如果不存在就创建
            if (!$count){
                return "用户不存在";
            }
            //联合查询
            $user = DB::table('users')
                    ->leftJoin('user_atts', 'user_atts.id', '=', 'users.id')
                    ->where('user_atts.id',$id)
                    ->first();
                    // ->get();
                    // dd($user);
            //显示网页        
            $user = ['u'=>$user];
            return view('Admin/member_show',$user);

    }
    public function right($id){
        $atts=user_att::where("att_id",$id)->first();
        if ($atts->right==="right") {
            $atts->right="false";

            $atts->save();
        }else{
            $atts->right="right";
            $atts->save();
        }
        return redirect('/Admin/user_list');

    }
    public function member_Grading(){
//        echo "member_Grading";
        return view('Admin/member_Grading');
    }
    public function integration(){
//        echo "integration";
        return view('Admin/integration');
    }

}
